//
//  PpNavgationViewController.swift
//  Palmpilot
//
//  Created by 杨伟毅 on 2018/10/19.
//  Copyright © 2018年 杨伟毅. All rights reserved.
//

import UIKit

class PpNavgationViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = nil
      
     
        initNavBar()
        // Do any additional setup after loading the view.
    }
    
    func initNavBar() {
        let navBar = UINavigationBar.appearance()
//         navBar.barTintColor = .black
        navBar.setBackgroundImage(UIImage.init(named: "top_nav"), for: .default)
         navBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
         navBar.isTranslucent = false
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.childViewControllers.count > 0 {
            let button = UIButton(type: .system)
            button.setImage(UIImage.init(named: "back")?.withRenderingMode(.alwaysOriginal), for: .normal)
            button.frame = ZCGRECT(x: 0, y: 0, width: 20, height: 20)
            let view = UIView() // 解决点击区域过大
            view.frame = ZCGRECT(x: 0, y: StatusHeight, width: 20, height: 20)
            view.addSubview(button)
            button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: view)
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    @objc func buttonAction() {
        self.popViewController(animated: true)
    }
    
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
